package com.onegene.pdf.util;

import cn.hutool.core.date.DateUtil;
import com.onegene.pdf.component.config.CommonParam;
import com.onegene.pdf.component.entity.PdfRequest;
import com.onegene.pdf.entity.SampleQueryVo;
import com.onegene.pdf.entity.SampleResultVo;

import java.util.Calendar;

/**
 * @author: laoliangliang
 * @description:
 * @create: 2020/7/28 11:44
 **/
public class PdfUtil {

    public static String getPrefixPath(CommonParam commonParam, PdfRequest pdfRequest){
        return commonParam.getPrefixPath() + pdfRequest.getTempSuffix() + "/" + commonParam.profile;
    }

    public static String getVersionName(SampleResultVo sampleResult) {
        Integer type = sampleResult.getType();
        if (type == 0) {
            return "(标准版)";
        }
        if (type == 1) {
            return "(标准版)";
        }
        if (type == 2) {
            return "(简化版)";
        }
        if (type == 3) {
            return "(早筛)";
        }
        Precondition.throwDataException("获取版本出错");
        return null;
    }

    public static void wrapStartEndTime(SampleQueryVo sampleQueryVo) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) - sampleQueryVo.getDays());
        sampleQueryVo.setStartTime(DateUtil.formatDateTime(calendar.getTime()));

        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) + sampleQueryVo.getDays() - 1);
        sampleQueryVo.setEndTime(DateUtil.formatDateTime(calendar.getTime()));
    }
}
